﻿using AD.Manage;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UDataBaseWork;
using XF.Common;
using XF.Meeting.DalFactory;
using XF.Meeting.Entity.CommonEntity;
using XF.Meeting.Entity.dbEntity;
using XF.Meeting.Entity.DTO;
using XF.Meeting.Entity.Query;
using XF.Meeting.Entity.View;
using XF.Meeting.IDal;
using XF.Sugar.IService;

namespace XF.Meeting.Service
{
    public class UserService : BaseService, IUserInfoService
    {





        private IUserDAL dal = null;

        public UserService(string Operator, string OperaIP)
        {
            this.Operator = Operator;
            this.OperaIP = OperaIP;
            if (dal == null)
            {
                lock (this.OperaIP)
                {
                    if (dal == null)
                    {
                        dal = DalFactory.DalFactory.GetUserDAL();
                    }
                }
            }
        }

        private UEntity.LogEntity.ELogRecordEntity LogEntity = new UEntity.LogEntity.ELogRecordEntity();

        public async Task<AuthInfo> Login(string UserName, string UserPassword)
        {
            List<int> ParentOrgIdList = new List<int>();
            var res = await dal.Login(UserName, UserPassword);

            switch (res.Item2)
            {
                case "":
                    var info = TableToList.ToList<AuthInfo>(res.Item1).FirstOrDefault();
                    if (info == null)
                    {
                        return info;
                    }
                    if (info.ParentOrgId != "" && info.ParentOrgId != null)
                    {
                        string[] arrStr = info.ParentOrgId.Split(',');//按逗号截取      
                        
                        ArrayList list = new ArrayList(arrStr);
                        list.RemoveAt(list.Count - 1);
                        list.RemoveAt(list.Count - 1);
                        info.ParentOrgIdList = list;
                    }
                    
                    info.ParentOrgId = info.ParentOrgIdList.ToString();
                    info.RegionalID = info.RegionalID == 0 ? 1 : info.RegionalID;
                    info.RegionalName = info.RegionalName == null ? "所有城市" : info.RegionalName;
                    info.Roles = info.IsAdmin==3 ? "Admin" : "User";
                    return info;
                default:
                    return null;
            }
        }
        public async Task<AuthInfo> Login(string phone)
        {
            var res = await dal.Login(phone);
            switch (res.Item2)
            {
                case "":
                    var info = TableToList.ToList<AuthInfo>(res.Item1).FirstOrDefault();
                    if (info == null)
                    {
                        return info;
                    }
                    info.RegionalID = info.RegionalID == 0 ? 1 : info.RegionalID;
                    info.RegionalName = info.RegionalName == null ? "所有区域" : info.RegionalName;
                    info.Roles = info.IsAdmin == 3 ? "Admin" : "User";
                    return info;
                default:
                    return null;
            }
        }

        public async Task<bool> UpdatePassword(string username, string password)
        {
            var res = await dal.UpdatePassword(username, password);
            return res.Item1;
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> InsertUserInfo(UserInfo entity)
        {
            //var entity = new UserInfo()
            //{
            //    Account = user.UserName,
            //    AccountName = user.RealName,
            //    IsAdmin = user.IsAdmin,
            //    IsEnable = user.IsEnable,
            //    Mail = user.Mail,
            //    Password = user.PassWord,
            //    Phone = user.Mobile,
            //    Position = user.PostName,
            //    RegionalID = user.AreaId,
            //    SourceType = 1
            //};
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.InsertUserInfo";
            LogEntity.OperateObject = "InsertUserInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserInfo>(entity);
            try
            {
                //var list = await GetUserInfoList(new UserQuery()
                //{
                //    Key = "",
                //    pageIndex = 1,
                //    pageSize = 1000000,
                //});
                //if(list.List != null  )
                //{
                //    if (list.List.Count > 0)
                //    {
                //        foreach (var item in list.List)
                //        {
                //            if (item.Account.Trim() == entity.Account.Trim())
                //            {
                //                bResult = false;
                //                strError = "已存在相同登录名的人员";
                //                return (bResult, strError);
                //            }
                //        }
                //    }

                //}


                var (ubResult,id) = await dal.InsertUserInfo(entity, out strError);
                if (!ubResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
                entity.ID = id;
                bResult = await dal.InsertUserOrgForOrgcalendarsAuth(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("InsertUserInfo Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 编辑用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateUserInfo(UserInfo entity)
        {

            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateUserInfo";
            LogEntity.OperateObject = "UpdateUserInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserInfo>(entity);
            try
            {
                //var list = await GetUserInfoList(new UserQuery()
                //{
                //    Key = "",
                //});
                //foreach (var item in list.List)
                //{
                //    if (item.Account.Trim() == entity.Account.Trim())
                //    {
                //        bResult = false;
                //        strError = "已存在相同登录名的人员";
                //        return (bResult, strError);
                //    }
                //}

                bResult = await dal.UpdateUserInfo(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
                bResult =await dal.DeleteUserOrgForOrgcalendarsAuth(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
                bResult =await dal.InsertUserOrgForOrgcalendarsAuth(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateUserInfo Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> DeleteUserInfoByID(UserInfo entity)
        {

            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.DeleteUserInfoByID";
            LogEntity.OperateObject = "DeleteUserInfoByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserInfo>(entity);
            try
            {


                bResult = await dal.DeleteUserInfoByID(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("DeleteUserInfoByID Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有人员信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<UserInfoForSearch>> GetUserInfoListByRID(UserQuery query)
        {
            PageList<UserInfoForSearch> list = new PageList<UserInfoForSearch>();
            List<UserInfoForSearch> userlist = new List<UserInfoForSearch>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetUserInfoListByRID";
            LogEntity.OperateObject = "GetUserInfoListByRID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetUserInfoListByRID(query, out strError);

                if (strError == "")
                {

                    list.List = TableToList.ToList<UserInfoForSearch>(res.Item1);


                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetUserInfoListByRID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            //RecordLog();
            return list;
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有人员信息(预约编辑数据回显)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<UserInfoForSearch>> GetUserInfoListByRIDForUpdate(UserQuery query)
        {
            PageList<UserInfoForSearch> list = new PageList<UserInfoForSearch>();
            List<UserInfoForSearch> userlist = new List<UserInfoForSearch>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCRoomByRID";
            LogEntity.OperateObject = "GetCRoomByRID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetUserInfoListByRID(query, out strError);

                if (strError == "")
                {

                    userlist = TableToList.ToList<UserInfoForSearch>(res.Item1);

                    string[] UserIDs = query.UserIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < UserIDs.Length; i++)
                    {
                        foreach (var item in userlist)
                        {
                            if (UserIDs[i] == item.ID.ToString())
                            {
                                item.IsChoice = true;
                            }
                        }
                    }
                    list.List = userlist;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetUserInfoByRID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            //RecordLog();
            return list;
        }

        /// <summary>
        /// 根据ID获取人员信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<UserInfo> GetUserInfoByID(UserQuery query)
        {
            UserInfo user = new UserInfo();
            List<UserInfo> list = new List<UserInfo>();
            List<RegionalInfo> orgList = new List<RegionalInfo>();
            List<int> IDs = new List<int>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetUserInfoByID";
            LogEntity.OperateObject = "GetUserInfoByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetUserInfoByID(query, out strError);

                if (strError == "")
                {
                    user = TableToList.ToList<UserInfo>(res.Item1).FirstOrDefault() ;
                    orgList = TableToList.ToList<RegionalInfo>(res.Item2);
                    foreach (var item in orgList)
                    {
                        user.OrgNames += item.RegionalName+",";
                        IDs.Add(item.ID);
                    }
                    user.OrgIDs = IDs;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetUserInfoByID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return user;
        }

        /// <summary>
        /// 根据查询关键字Key获取所有人员信息（少字段：名称，职位）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<UserInfoForSearch>> GetUserInfoListByKey(UserQuery query)
        {

            PageList<UserInfoForSearch> list = new PageList<UserInfoForSearch>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetUserInfoByKey";
            LogEntity.OperateObject = "GetUserInfoByKey";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetUserInfoListByKey(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<UserInfoForSearch>(res.Item1);
                    //if(query.UserIDs!=null&& query.UserIDs!="")
                    //{
                    //    string[] userIDs = query.UserIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    //    if (list.List.Count > 0 && list.List != null && userIDs.Length > 0 && userIDs != null)
                    //    {
                    //        for (int i = 0; i < userIDs.Length; i++)
                    //        {
                    //            foreach (var item in list.List)
                    //            {
                    //                if (item.ID.ToString() == userIDs[i])
                    //                {
                    //                    list.List.Remove(item);
                    //                }
                    //            }
                    //        }
                    //    }
                    //}
                                    
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetUserInfoByKey Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据查询关键字Key获取所有人员信息(多字段)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<UserInfo>> GetUserInfoList(UserQuery query)
        {
            PageList<UserInfo> list = new PageList<UserInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetUserInfoList";
            LogEntity.OperateObject = "GetUserInfoList";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetUserInfoList(query, out strError);

                if (strError == "")
                {
                    var userInfoList = TableToList.ToList<UserInfo>(res.Item1);
                    foreach (var item in userInfoList)
                    {
                        item.CreatedTime = item.WhenCreated.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    list.List = userInfoList;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetUserInfoList Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据用户ID获取用户积分
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<UserIntegral> GetUserIntegral(UserQuery query)
        {
            List<UserIntegral> list = new List<UserIntegral>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetUserIntegral";
            LogEntity.OperateObject = "GetUserIntegral";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetUserIntegral(query, out strError);

                if (strError == "")
                {
                    list = TableToList.ToList<UserIntegral>(res.Item1);
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetUserIntegral Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list[0];
        }

        /// <summary>
        /// 编辑用户积分
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateUserIntegral(UserIntegral entity)
        {

            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateUserIntegral";
            LogEntity.OperateObject = "UpdateUserIntegral";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserIntegral>(entity);
            try
            {


                bResult = await dal.UpdateUserIntegral(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateUserIntegral Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 修改用户区域
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateUserRegional(UserInfo entity)
        {

            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateUserRegional";
            LogEntity.OperateObject = "UpdateUserRegional";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserInfo>(entity);
            try
            {


                bResult = await dal.UpdateUserRegional(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateUserRegional Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 导入ad用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> ADuserSYNC()
        {
            ADSync sync = new ADSync();
            string strSqlConn = UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"]));
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.ADuserSYNC";
            LogEntity.OperateObject = "ADuserSYNC";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {

                if (!await sync.ADSyncManage())
                {
                    bResult = false;
                    LogEntity.OperateResult = "Fail";
                }


            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("ADuserSYNC Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }
        /// <summary>
        /// 获取白名单用户
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<WhiteList>> GetWhiteList(UserQuery query)
        {

            PageList<WhiteList> list = new PageList<WhiteList>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetWhiteList";
            LogEntity.OperateObject = "GetWhiteList";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<UserQuery>(query);
            try
            {
                var res = await dal.GetWhiteList(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<WhiteList>(res.Item1);                    
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetWhiteList Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        /// <summary>
        /// 新增白名单用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> InsertUserToWhiteList(WhiteListUser entity)
        {

            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.InsertUserToWhiteList";
            LogEntity.OperateObject = "InsertUserToWhiteList";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<WhiteListUser>(entity);
            try
            {
                if(entity.userids.Count>0&& entity.userids!=null)
                {
                    foreach (var item in entity.userids)
                    {
                        bResult = await dal.InsertUserToWhiteList(item, out strError);
                        if (!bResult)
                        {
                            LogEntity.OperateResult = "Fail";
                            bResult = false;
                        }
                    }                    
                }               
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("InsertUserToWhiteList Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }
        /// <summary>
        /// 修改白名单用户企业微信通知
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateToWhiteListUserMsg(WhiteListUser entity)
        {

            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateToWhiteListUserMsg";
            LogEntity.OperateObject = "UpdateToWhiteListUserMsg";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<WhiteListUser>(entity);
            try
            {
               
                        bResult = await dal.UpdateToWhiteListUserMsg(entity, out strError);
                        if (!bResult)
                        {
                            LogEntity.OperateResult = "Fail";
                            bResult = false;
                        }
                
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateToWhiteListUserMsg Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }
        /// <summary>
        /// 修改白名单用户企业微信日程推送
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateToWhiteListUserSchedule(WhiteListUser entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateToWhiteListUserSchedule";
            LogEntity.OperateObject = "UpdateToWhiteListUserSchedule";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<WhiteListUser>(entity);
            try
            {
                bResult = await dal.UpdateToWhiteListUserSchedule(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateToWhiteListUserSchedule Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }
        /// <summary>
        /// 删除白名单用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> DeleteToWhiteListUser(WhiteListUser entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.DeleteToWhiteListUser";
            LogEntity.OperateObject = "DeleteToWhiteListUser";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<WhiteListUser>(entity);
            try
            {
                bResult = await dal.DeleteToWhiteListUser(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("DeleteToWhiteListUser Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 系统日志
        /// </summary>
        private void RecordLog()
        {
            LogEntity.Operator = Operator;
            LogEntity.OperateIP = OperaIP;
            ULogWork.CLogToDataBase.RecordOperateLog(LogEntity);
        }


    }
}
